const { localUrl } = require("../../utils/util")

// pages/changeinfo/changeinfo.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
    radio: '1',
    userchange: {
      id: '',
      age: '',
      avatar: '',
      mobile: '',
      nickname: '',
      sex: '',
      sign: '',
     
    },
    password: ''
    
  },
  onChangenickname(event){
    this.setData({
      'userchange.nickname':event.detail
    })
  },
  onChangemobile(event){
    this.setData({
      'userchange.mobile':event.detail
    })
  },

  onChangepwd(event){
    this.setData({
      password:event.detail
    })
    
  },
  onChangesign(event){
    this.setData({
      'userchange.sign':event.detail
    })
  },
  onChangeage(event) {
    // event.detail 为当前输入的值
    console.log(event.detail);
    this.setData({
      'userchange.age':event.detail
    })
  },
  onChange(event) {
    this.setData({
      radio: event.detail,
      'userchange.sex':event.detail
    });
  },
  tijiao(){

    wx.request({
      url: localUrl+'/ucenter/member/changeInfo',
      method:'POST',
      data:{
        "age": this.data.userchange.age,
        "avatar": this.data.userchange.avatar,

        "id": this.data.user.id,
 
        "nickname": this.data.userchange.nickname,
        "sex": this.data.userchange.sex,
        "sign":this.data.userchange.sign
      },
    
      success(res){
        console.log(res)
        wx.showToast({
          title: '修改成功',
          icon:'success'
        })
      }
    
    })
    wx.navigateTo({
      url: '/pages/user/user',
    
    })
    
  },
 
  setAvator(){
    var that = this 
    // 上传图片 获取路径 
    wx.chooseImage({ 
     success: function (res) { 
      console.log('临时路径：' + res.tempFilePaths[0]) 
        wx.uploadFile({ 
         url:localUrl+'/oss/avator', 
         filePath: res.tempFilePaths[0], 
         name: 'file', 
         success: function (result) { 
          console.log("返回路径：" + result.data) 
          var  imginfo=JSON.parse(result.data)
          console.log(imginfo)
          that.setData({
            'userchange.avatar':imginfo.data.url
          })
         } 
        }) 
     }, 
    }) 
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.setData({
      user: wx.getStorageSync('user')

    })
   

  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
      this.setData({
    
        'userchange.age':this.data.user.age,
        'userchange.avatar':this.data.user.avatar,
        'userchange.id':this.data.user.id,
        'userchange.mobile':this.data.user.mobile,
        'userchange.nickname':this.data.user.nickname,
        'userchange.sex':this.data.user.sex,
        'userchange.sign':this.data.user.sign,
      })
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})